﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ENTIDADES;
using System.Data;

namespace DATA
{
    public class dPedido
    {
        public eJQGrid listadoPedido(string sidx, string sord, int page, int rows)
        {

            DataTable dt = MetodoDatos.listaDT("exec uspListarEntidades 1,'Pedido'");

            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize = rows;
            int totalRecords = dt.Rows.Count;
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

            var GridData = new eJQGrid
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = (
                    from DataRow dr in dt.Rows
                    select new
                    {
                        i = Convert.ToString(dr["idcabecerapedido"]),
                        cell = new string[]{
                         Convert.ToString(dr["idcabecerapedido"]),                         
                         Convert.ToString(dr["idmesa"]),
                         Convert.ToString(dr["mesa"]),
                         //Convert.ToString(Convert.ToDateTime(dr["fecha"]).ToShortDateString()),
                         Convert.ToString(dr["idcliente"]),
                         Convert.ToString(dr["cliente"]),
                         Convert.ToString(dr["idempleado"]),
                         Convert.ToString(dr["ruc"])
                     }
                    }).ToArray()
            };
            return GridData;
        }
            /*DataTable dt = MetodoDatos.listaDT("exec uspListarEntidades 1,'DetallePedido'");

            int pageIndex = Convert.ToInt32(page) - 1;
            int pageSize = rows;
            int totalRecords = dt.Rows.Count;
            int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);

            var GridData = new eJQGrid
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = (
                    from DataRow dr in dt.Rows
                    select new
                    {
                        i = Convert.ToString(dr["idcabecerapedido"]),
                        cell = new string[]{
                         Convert.ToString(dr["idcabecerapedido"]),                         
                         Convert.ToString(dr["idmesa"]),
                         Convert.ToString(dr["mesa"]),
                         //Convert.ToString(Convert.ToDateTime(dr["fecha"]).ToShortDateString()),
                         Convert.ToString(dr["idcliente"]),
                         Convert.ToString(dr["cliente"]),
                         Convert.ToString(dr["idmozo"]),
                         Convert.ToString(dr["mozo"]),
                         Convert.ToString(dr["cantidad"]),
                         Convert.ToString(dr["precio"])                    
                     }
                    }).ToArray()
            };
            return GridData;
        }*/

    }
}
